# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=shapelib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=1
pkgdesc="simple C API for reading and writing ESRI Shapefiles (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="http://shapelib.maptools.org/"
msys2_references=(
  "cpe: cpe:2.3:a:osgeo:shapelib"
)
license=("LGPL" "MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://download.osgeo.org/shapelib/${_realname}-${pkgver}.tar.gz"
        "https://github.com/OSGeo/shapelib/commit/316ff872566ea0d91d6b62fe01bfe39931db39aa.patch")
sha256sums=('19528b24377241705637320c367943031ad5088665d1fb0e1eaa52a71264a6c4'
            'd04bb2359ef412eb7715c49cf71e64a5327c35557bb9e4a359fbd6a43c84782c')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/316ff872566ea0d91d6b62fe01bfe39931db39aa.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  #export lt_cv_deplibs_check_method='pass_all'

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
